/*
 * daemonizer.h
 *
 *  Created on: 14.03.2013
 *      Author: Lapchinskiy
 */

#ifndef DAEMONIZER_H_
#define DAEMONIZER_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define OPEN_MAX_GUESS 93
/////////////////////Methods declaration////////////////////////////
void setTidyUpMethod(void (*method)(void));
int BecomeDaemonProcess(const char *const lockFileName,
								const char *const logPrefix,
								const int logLevel,
								int *const lockFileDesc,
								int *const thisPID);
int ConfigureSignalHandlers(void);
int BindPassiveSocket(const unsigned long interfaceAddress,
							 const int portNum,
							 int *const boundSocket);
int AcceptConnections(const int master);
int HandleConnection(const int slave);
int WriteToSocket(const int sock,const char *const buffer,
						const size_t buflen);
int ReadLine(const int sock,char *const buffer,const size_t buflen,
				 size_t *const bytesRead);
void FatalSigHandler(int sig);
void TermHandler(int sig);
void HupHandler(int sig);
void Usr1Handler(int sig);
void TidyUp(void);
/////////////////////Methods declaration////////////////////////////
#endif /* DAEMONIZER_H_ */
